package com.corewillsoft.fireflies.util;

import android.content.Context;
import android.util.DisplayMetrics;

public class ScreenUtils {
	private static ScreenUtils instance;
	
	private float scaleRatio;
	private DisplayMetrics metrics;
	
	public static void initInstance(Context context) {
		instance = new ScreenUtils(context);
	}
	
	public static ScreenUtils getInstance() {
		return instance;
	}
	
	private ScreenUtils(Context context) {
		metrics = context.getResources().getDisplayMetrics();
		scaleRatio = 1;
		switch (metrics.densityDpi) {
		case DisplayMetrics.DENSITY_LOW:
			scaleRatio = (float) 0.5;
			break;
		case DisplayMetrics.DENSITY_MEDIUM:
			scaleRatio = 1;
			break;
		case DisplayMetrics.DENSITY_HIGH:
			scaleRatio = (float) 1.2;
			break;
		case DisplayMetrics.DENSITY_XHIGH:
			scaleRatio = (float) 1.5;
			break;
		default:
			break;	
		}
	}
	
	public float getRelativeWidth() {
		return metrics.widthPixels / scaleRatio;
	}
	
	public float getRelativeHeight() {
		return metrics.heightPixels / scaleRatio;
	}
	
	public float getScaleRatio() {
		return scaleRatio;
	}
}
